package com.feng.common.config;

import com.feng.common.exceptions.PathException;
import com.feng.common.exceptions.ServiceException;
import com.feng.common.vo.ApiRest;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author feng
 * @describe
 */
@RestControllerAdvice
public class GlobalExceptionConfig {
    @ExceptionHandler(ServiceException.class)
    public ApiRest serviceEx(ServiceException e) {
        e.printStackTrace();
        return ApiRest.failure(e.getMessage(), null);
    }

    @ExceptionHandler(PathException.class)
    public ApiRest pathEx(PathException e) {
        e.printStackTrace();
        return ApiRest.failure(e.getMessage(), null);
    }

    @ExceptionHandler(Exception.class)
    public ApiRest ex(Exception e) {
        e.printStackTrace();
        return ApiRest.failure("服务器繁忙", null);
    }
}
